<template>
    <div>
        <van-nav-bar title="我的订单" left-text="返回" left-arrow @click-left="() => { { $router.back('/') } }" />


        <van-tabs v-model:active="active" @change="onchange">

            <van-tab title="全部订单1"></van-tab>
            <van-tab title="待付款"></van-tab>
            <van-tab title="待发货"></van-tab>
            <!-- <van-tab title="空"> <van-empty  description="没有订单" /></van-tab> -->

        </van-tabs>
        <van-cell-group v-for="item in fech">
            <van-cell @click="ddbh" title="订单编号" :value="item.orderId" />
            <van-cell title="时间" :value="item.create_time" />
            <van-cell title="描述" :value="item.product_code" />
            <van-cell title="状态" :value="item.status == 1 ? '待支付' : '代发货'" />
            <van-cell title="价格" :value="(item.totalPrice / 100).toFixed(2)" />
            <van-cell title="名字" :value="item.username" />

        </van-cell-group>
        
    </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router';
const router = useRouter()
let username = localStorage.getItem('username')
console.log(username);
import { getOrderListApi } from '@/api/api';
let getdata = ref([])
let fech = ref([])
getOrderListApi(username).then(res => {
    console.log('订单列表', res);
    getdata.value = res.data.data
    fech.value = getdata.value
})

const onchange = (index) => {
    if (index == 2) {
        fech.value = getdata.value.filter(item => item.status == 2)
    }
    if (index == 1) {
        fech.value = getdata.value.filter(item => item.status == 1)
    }
    if (index == 0) {
        fech.value = getdata.value
    }
}

const ddbh = () => {
    router.push('/detail/index')
}

// let time=
</script>

<style lang="scss" scoped></style>